/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * All Rights Researved.
 *
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 *
 * @author: jin Chen 
 * @date: Dec 6, 2003$
 * @version: 1.0
 */
package edu.psu.geovista.app.pcp.plot.control.tools;

import javax.swing.*;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyVetoException;
import java.beans.VetoableChangeListener;

public class InternalFrameToFrame extends JInternalFrame implements InternalFrameListener,VetoableChangeListener{

    public InternalFrameToFrame(String title, boolean resizable, boolean closable, boolean maximizable, boolean iconifiable) {
        super(title, resizable, closable, maximizable, iconifiable);
        this.addInternalFrameListener(this);
        this.addVetoableChangeListener(this);

    }

    public void internalFrameOpened(InternalFrameEvent e) {
        System.out.println("open");
    }

    public void internalFrameClosing(InternalFrameEvent e) {
        System.out.println("closing");
    }

    public void internalFrameClosed(InternalFrameEvent e) {
        System.out.println("Closed");
    }

    public void internalFrameIconified(InternalFrameEvent e) {
        System.out.println("Iconfied");
        JFrame myf=new JFrame();
        JComponent comp=(JComponent) this.getContentPane().getComponents()[0];
        if(comp!=null)
        myf.getContentPane().add(comp);
        myf.setBounds(100,100,100,100);
        myf.setVisible(true);

    }

    public void internalFrameDeiconified(InternalFrameEvent e) {
        System.out.println("deInconfied");
    }

    public void internalFrameActivated(InternalFrameEvent e) {
        System.out.println("Actived");
    }

    public void internalFrameDeactivated(InternalFrameEvent e) {
        System.out.println("Deactived");
    }

    public void vetoableChange(PropertyChangeEvent evt)
            throws PropertyVetoException {
        String name=evt.getPropertyName() ;

        System.out.println("property:"+name);
        if(name.equals(JInternalFrame.IS_CLOSED_PROPERTY ) ){
            System.out.println("throw close cancel!");
            throw new PropertyVetoException("close cancel",evt);
        }
    }

   


}
